package org.admin.controller;

import core.Data;
import core.data.DataResult;
import org.admin.entity.dto.RoleDto;
import org.admin.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/role")
public class RoleController {
    @Autowired
    RoleService service;
    // 创建更新角色
    @PostMapping("/create")
    public DataResult create(@RequestBody Map<String, Object> post){
        return Data.create(post)
                .<RoleDto>addHandle("params", data -> {
                    new RoleDto().validate(new String[] {
                        "id", "*name", "*upload"
                    }).check(data);
                }).addHandle("create", service::create)
                .start().getResult();
    }

    @GetMapping("/fetch")
    public DataResult fetch(@RequestParam Map<String, Object> get){
        return Data.create(get)
                .<RoleDto>addHandle("params", data -> {
                    new RoleDto().validate(new String[]{
                            "*id"
                    }).check(data);
                }).addHandle("fetch", service::fetch)
                .start().getResult();
    }
    // 删除 批量删除
    @PostMapping("/remove")
    public DataResult remove(@RequestBody Map<String, Object> post){
        return Data.create(post)
                .<RoleDto>addHandle("params", data -> {
                    new RoleDto().validate(new String[]{
                            "ids"
                    }).check(data);
                }).addHandle("remove", service::remove)
                .start().getResult();
    }

    // 获取角色列表
    @GetMapping("/query")
    public DataResult query(@RequestParam Map<String, Object> get){
        return Data.create(get)
                .<RoleDto>addHandle("params", data -> {
                    new RoleDto().validate(new String[]{
                            "name", "upload", "current", "size"
                    }).check(data);
                }).addHandle("query", service::query)
                .start().getResult();
    }

    /*

    // 获取角色信息
    public DataResult info(){
    }

    // 角色应用菜单
    public DataResult appMenu() {

    }

     */
}
